package main

import (
	"fmt"
	"sync"
	"time"
)

var once sync.Once

func f1(ch, src chan int) {
	for {
		v, ok := <-src
		if !ok {
			break
		}
		ch <- 2 * v
	}

	once.Do(func() {
		close(ch)
	})
}

//有bug，未知原因
func main() {
	src := make(chan int, 2)
	ch := make(chan int, 2)
	go func() {
		fmt.Println("1")
		src <- 1
		src <- 2
		close(src)
	}()

	go f1(ch, src)
	go f1(ch, src)

	time.Sleep(5 * time.Second)

	for v := range ch {
		fmt.Print(v, " ")
	}

}
